/**
 * 战绩详情
 * Created by duwei on 2018/6/4.
 */
var RecordDetailWindow = Window.extend({
    _ccsFileName:res.RecordDetailWindow_json,
    _itemWidth:1264,
    _itemHeight:102,
    playerCount: 9,
    data: null,
    /**
     * 初始化
     */
    initWindow: function (data) {
        Window.prototype.onEnter.call(this);
        this.data=data;
        this._initRecordDetailWindow();
    },
    /**
     * 初始化界面
     * @private
     */
    _initRecordDetailWindow: function () {
        var self = this;
        var info = self._nodeList["_info"];
        var Count = 0;
        for (var i = 1; i <= 9; i++) {
            if (self.data["nickname" + i]) {
                Count++
            } else {
                break;
            }
        }
        if (Count < 4) {
            self.startPosx = (info["nickname1"].getPositionX() + info["nickname2"].getPositionX()) / 2;
            self.endPosx = (info["nickname3"].getPositionX() + info["nickname4"].getPositionX()) / 2;
        } else {
            self.startPosx = info["nickname1"].getPositionX();
            self.endPosx = info["nickname4"].getPositionX();
        }
        self.interval = (self.endPosx - self.startPosx) / (Count - 1);
        for (var i = 1; i <= self.playerCount; i++) {
            var name = info["nickname" + i];
            if (self.data["nickname" + i]) {
                name.setString(ellipsisStr(self.data["nickname" + i], 6));
                name.setPositionX(self.startPosx + self.interval * (i - 1));
            } else if (name) {
                name.setVisible(false);
            }
        }
        self._dataScroll = self._nodeList['_dataScroll'];
        self.createContent();
        self.itemList = self.data['result_arr'];
        tableViewRefresh(self.tableView);
    },
    createContent: function () {
        var self = this;
        if (self.tableView) {
            self.tableView.removeFromParent();
            self.tableView = null;
            self.itemList = [];
        }
        var tableView = new cc.TableView(self, cc.size(self._dataScroll.getContentSize().width, self._dataScroll.getContentSize().height));
        tableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
        tableView.setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN);
        tableView.x = 0;
        tableView.y = 0;
        tableView.setDelegate(this);
        tableView.setBounceable(true);
        self._dataScroll.getParent().addChild(tableView);
        tableView.setPosition(self._dataScroll.getPosition());
        self._dataScroll.setVisible(false);
        self.tableView = tableView;
    },
    tableCellTouched: function (table, cell) {

    },
    tableCellSizeForIndex: function () {
        return cc.size(this._itemWidth, this._itemHeight);
    },
    tableCellAtIndex: function (table, idx) {
        var self = this;
        var cell = table.dequeueCell();
        var node = null;
        if (cell == null) {
            cell = new cc.TableViewCell();
            node = addItem('RecordDetailCellItem', cell,idx, self.data);
            node.setName("itemCell");
        } else {
            node = cell.getChildByName("itemCell")
            node.setData(idx, self.data);
        }
        return cell;
    },
    numberOfCellsInTableView: function () {
        if (this.itemList == null) return 0;
        return this.itemList.length;
    }
});